import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/site/widgets/statistics_itme_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年05月14日 09:19
 */
class SiteOverViewWidgets extends StatelessWidget {
  final List<String> titleList;
  final Map<String,dynamic> energyData;
  final String monetaryUnitName;
  const SiteOverViewWidgets({required this.energyData,required this.monetaryUnitName,  required this.titleList,super.key});

  @override
  Widget build(BuildContext context) {
    Log.d('energyData==' + energyData.toString());
    /// 1 今日光伏自发电量 光伏发电	2储能充电量 储能放电量  3充电桩充电量 	4负载用电量  	5市电电量
    bool isShowEs = false;
    bool isShowPv = false;
    bool isShowCharge = false;
    bool isShowLoad = false;
    bool isShowMain = false;
    if(energyData != null){
      List tempList = energyData['flag']??[];
      List typeList = [];
      if(tempList  != null && tempList.isNotEmpty ){
        for (var element in tempList) {
            /// 1 今日光伏自发电量 光伏发电	2储能充电量 储能放电量  3充电桩充电量 	4负载用电量  	5市电电量
            if (element['code'] == 1 && element['flag'] == true) {
              isShowPv = true;
              typeList.add(isShowPv);
            } else if (element['code'] == 2 && element['flag'] == true) {
              isShowEs = true;
              typeList.add(isShowEs);
            } else if (element['code'] == 3 && element['flag'] == true) {
              isShowCharge = true;
              typeList.add(isShowCharge);
            } else if (element['code'] == 4 && element['flag'] == true) {
              isShowLoad = true;
            } else if (element['code'] == 5 && element['flag'] == true) {
              isShowMain = true;
            }
        }
        Widget allProfitWidget = Container();
        Widget mainWidget = Container();
        Widget pvWidget = Container();
        Widget essWidget = Container();
        Widget chargeWidget = Container();
        Widget otherLoadWidget = Container();
        if(typeList.length >= 2 ){//光伏储能 充电桩三种开关大于等于2则显示总收益,否则不显示
          allProfitWidget = Row(
            children: [
              Expanded(child: StatisticsItemWidget(
                titleList[0],
                energyData['totalGains']!=null?energyData['totalGains'].toString():'--',
                ResKey.yuan.tr,
                monetaryUnitName,
                isHome: true,
              ),
              ),
              Gaps.hGap16,
            ],
          );
        }
        if(isShowMain){
          mainWidget = Container(
            margin: EdgeInsets.only(top: 10),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    Row(
                      children: [
                        StatisticsItemWidget(titleList[1], energyData['mainsUse'] != null?energyData['mainsUse'].toString():'--', 'kWh',
                            monetaryUnitName),
                        Gaps.hGap10,
                        StatisticsItemWidget(titleList[2], energyData['mainsFeed'] != null?energyData['mainsFeed'].toString():'--', 'kWh',
                            monetaryUnitName),
                      ],
                    ),
                  ],
                ),
          );
        }
        if(isShowPv){
          pvWidget = Container(
            margin: EdgeInsets.only(top: 10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Row(
                  children: [
                    StatisticsItemWidget(titleList[3], energyData['pvSolar'] != null?energyData['pvSolar'].toString():'--', 'kWh',
                        monetaryUnitName),
                    Gaps.hGap10,
                    StatisticsItemWidget(titleList[4], energyData['photovoltaicGains'] != null?energyData['photovoltaicGains'].toString():'--', ResKey.yuan.tr,
                        monetaryUnitName ),
                  ],
                ),
                Gaps.vGap10,
              ],
            ),
          );
        }
        return  Container(
          margin: EdgeInsets.only(left: 16.w,right: 16.w),
          padding: EdgeInsets.only(left: 16.w,top: 16.w),
          decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(8))),
          child: Column(
            children: [
              allProfitWidget,
              mainWidget,
              pvWidget,
              essWidget,
              chargeWidget,
              otherLoadWidget
            ],
          ),
        );
      }else{
        return Container();
      }
    }else{
      return Container();
    }



  }
}
